/*  Copyright (c) 2012 William Rogers and James Boud

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

using System;
using System.Collections.Generic;
using SlimDX;
using SlimDX.Direct3D11;

namespace JBBRXG11
{
    public class EffectTechnique
    {
        Effect parent;
        GraphicsDevice device;
        SlimDX.Direct3D11.EffectTechnique dxtechnique;

        internal SlimDX.Direct3D11.EffectTechnique DXTechnique { get { return dxtechnique; } }

        internal EffectTechnique(Effect par,
                                 JBBRXG11.GraphicsDevice dev,
                                 SlimDX.Direct3D11.EffectTechnique dxtech)
        {
            parent = par;
            device = dev;
            dxtechnique = dxtech;
        }

        public string Name
        {
            get { return dxtechnique.Description.Name; }
        }

        public EffectPassCollection Passes
        {
            get
            {
                return new EffectPassCollection(parent, device, dxtechnique);
            }
        }
    }

    public class EffectPassCollection : IEnumerable<EffectPass>, IEnumerator<EffectPass>
    {
        Effect parent;
        GraphicsDevice device;
        int current;
        SlimDX.Direct3D11.EffectTechnique dxtechnique;

        internal EffectPassCollection(Effect par, GraphicsDevice dev, SlimDX.Direct3D11.EffectTechnique dxtech)
        {
            parent = par;
            device = dev;
            dxtechnique = dxtech;
            current = -1;
        }

        public int Count { get { return dxtechnique.Description.PassCount; } }
        public EffectPass this[int index]
        {
            get { return new EffectPass(parent, device, dxtechnique.GetPassByIndex(index)); }
        }
        public EffectPass this[string name]
        {
            get { return new EffectPass(parent, device, dxtechnique.GetPassByName(name)); }
        }
        public IEnumerator<EffectPass> GetEnumerator() { return this; }
        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { return this; }
        public EffectPass Current { get { return this[current]; } }
        public void Dispose() { }
        object System.Collections.IEnumerator.Current { get { return this[current]; } }
        public bool MoveNext() { current++; return current < Count; }
        public void Reset() { current = -1; }
    }
}


/*





        // Summary:
        //     Gets the EffectAnnotation objects associated with this technique.
        public EffectAnnotationCollection Annotations { get; }

        // Summary:
        //     Determines whether a given EffectParameter is used by this technique.
        //
        // Parameters:
        //   parameter:
        //     The effect parameter to check.
        public bool IsParameterUsed(EffectParameter parameter);
        //
        // Summary:
        //     Validates this technique.
        public bool Validate();*/
